import request from '@/utils/request.js'
import { useTokenStore } from '@/stores/token.js';
//商品分类查询
export const categoryListService = () =>{
   
    return request.get('/categories')
}

//添加分类
export const addCategoryService = (categoryData) =>{
    return request.post('/categories',categoryData)
}

//删除分类
export const delCategoryService = (id)=>{
    const url = `/categories/${id}`
   return request.delete(url)
}

//查询products
export const productsListService = (id) =>{
    const url = `/categories/${id}/products`
    return request.get(url)
}

//添加product
export const addProductService = (DataObj) =>{
    const id1 = DataObj.id
    const id = Number(id1)
    const url = `/categories/${id}/products`
    return request.post(url,DataObj.requestBody)
}

//删除product
export const delProductService=(DataObj)=>{
    const id1 = DataObj.id1
    const id2 = DataObj.id2
    const url = `/categories/${id1}/products/${id2}`
    return request.delete(url)
}

//获得item列表
export const itemListService=(id) =>{
    const url = `/products/${id}/items`
    return request.get(url)
}

//添加item
export const addItemService=(DataObj)=>{
    const url = `/products/${DataObj.id1}/items`
    return request.post(url,DataObj.body)
}

//删除
export const delItemService=(DataObj)=>{
    const url = `/products/${DataObj.id1}/items/${DataObj.id2}`
    return request.delete(url)
}

//修改
export const editItemService=(DataObj)=>{
    const url = `/products/${DataObj.id1}/items/${DataObj.id2}`
    return request.put(url,DataObj.body)
}